//
//  LzwAdresstableViewCell.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/1.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwAdresstableViewCell.h"
#import "LzwBaseLable.h"
#import "LzwBaseImageView.h"
#import "LzwBaseButton.h"
#import "UIImageView+WebCache.h"
#import "LzwSingleton.h"

@interface LzwAdresstableViewCell ()

@property (nonatomic, retain) LzwBaseLable *LableAdree1;
@property (nonatomic, retain) LzwBaseLable *LableAdree2;
@property (nonatomic, retain) LzwBaseLable *LableAdree3;
@property (nonatomic, retain) LzwBaseLable *LableAdree4;
@property (nonatomic, retain) LzwBaseLable *LableAdree5;
@property (nonatomic, retain) LzwBaseLable *LableAdree6;

@property (nonatomic, retain) LzwBaseImageView *ImageView1;
@property (nonatomic, retain) LzwBaseImageView *ImageView2;
@property (nonatomic, retain) LzwBaseImageView *ImageView3;
@property (nonatomic, retain) LzwBaseImageView *ImageView5;

@property (nonatomic, retain) LzwBaseButton *buttonGZ;
@property (nonatomic, retain) LzwBaseButton *buttonLike;
@property (nonatomic, retain) LzwBaseButton *buttonShop;


@property (nonatomic, retain) UIButton *bottomButton;

@end

@implementation LzwAdresstableViewCell

-(void)dealloc{
    [_LableAdree1 release];
    [_LableAdree2 release];
    [_LableAdree3 release];
    [_LableAdree4 release];
    [_LableAdree5 release];
    [_LableAdree6 release];
    
    [_ImageView1 release];
    [_ImageView2 release];
    [_ImageView3 release];
    [_ImageView5 release];
    
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self creat];
    }
    return self;
    
}

-(void)creat{
    
    //物品主人头像
    self.ImageView1 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(5 * WIDTH, 5 * WIDTH, 35 * WIDTH, 35 * WIDTH)];
    [self.ImageView1.layer setMasksToBounds:YES];
    [self.ImageView1.layer setCornerRadius:17.5 * WIDTH];
    [self.contentView addSubview:self.ImageView1];
    
    //人物姓名
    self.LableAdree1 = [[LzwBaseLable alloc]initWithFrame:CGRectMake(50 * WIDTH, 5 * WIDTH, 150 * WIDTH, 20 * WIDTH)];
    self.LableAdree1.textColor = [UIColor lightGrayColor];
    self.LableAdree1.font = [UIFont systemFontOfSize:15 * WIDTH];
    [self.contentView addSubview:self.LableAdree1];
    
    //更新时间
    self.LableAdree2 = [[LzwBaseLable alloc]initWithFrame:CGRectMake(50 * WIDTH, 30 * WIDTH, 160 * WIDTH, 20 * WIDTH)];
//    self.LableAdree2.backgroundColor = [UIColor purpleColor];
    self.LableAdree2.textColor = [UIColor lightGrayColor];
    self.LableAdree2.font = [UIFont systemFontOfSize:10 * WIDTH];
    [self.contentView addSubview:self.LableAdree2];
    
    //皇冠
    self.ImageView2 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(250 * WIDTH, 10 * WIDTH, 30 * WIDTH, 30 * WIDTH)];
    self.ImageView2.image = [UIImage imageNamed:@"huang.png"];
    //    self.bottomImageView2.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:self.ImageView2];
    
    //关注按钮
    self.bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.bottomButton.frame = CGRectMake(290 * WIDTH, 15 * WIDTH, 60 * WIDTH, 20 * WIDTH);
    [self.bottomButton setTitle:@"关注" forState:UIControlStateNormal];
    [self.bottomButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    self.bottomButton.titleLabel.font = [UIFont systemFontOfSize:14 * WIDTH];
    self.bottomButton.layer.cornerRadius = 10 * WIDTH;
    self.bottomButton.layer.masksToBounds = YES;
    
    [self.bottomButton.layer setBorderWidth:0.4 * WIDTH];
    self.bottomButton.layer.borderColor=[UIColor redColor].CGColor;
    [self.contentView addSubview:self.bottomButton];
    
    
    //添加关注按钮触发事件
    [self.bottomButton addTarget:self action:@selector(ButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    //图片
    self.ImageView3 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 50 * WIDTH, 375 * WIDTH, 300 * WIDTH)];
    self.ImageView3.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.ImageView3];
    
    //描述
    self.LableAdree3 = [[LzwBaseLable alloc]initWithFrame:CGRectMake(10 * WIDTH, 360 * WIDTH, 355 * WIDTH, 80 * WIDTH)];
    self.LableAdree3.numberOfLines = 0;
    self.LableAdree3.font = [UIFont systemFontOfSize:15 * WIDTH];
    self.LableAdree3.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.LableAdree3];
    
    //喜爱人数
    self.LableAdree6 = [[LzwBaseLable alloc]initWithFrame:CGRectMake(100 * WIDTH, 450 * WIDTH, 100 * WIDTH, 20 * WIDTH)];
    self.LableAdree6.textColor = [UIColor lightGrayColor];
    self.LableAdree6.font = [UIFont systemFontOfSize:17 * WIDTH];
    [self.contentView addSubview:self.LableAdree6];
    
    //喜爱
//    self.buttonLike = [[LzwBaseButton alloc]initWithFrame:CGRectMake(50, 450, 100, 20)];
    LzwBaseImageView *image1 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(70 * WIDTH, 450 * WIDTH, 20 * WIDTH, 20 * WIDTH)];
    image1.image = [UIImage imageNamed:@"redLove.png"];
//    [self.buttonLike addSubview:image1];
    [self.contentView addSubview:image1];
    
    //购物车图片
    self.buttonShop = [[LzwBaseButton alloc]initWithFrame:CGRectMake(240 * WIDTH, 450 * WIDTH, 100 * WIDTH, 20 * WIDTH)];

    LzwBaseImageView *image = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 0, 20 * WIDTH, 20 * WIDTH)];
    image.image = [UIImage imageNamed:@"Shopcar.png"];
    [self.buttonShop addSubview:image];
    LzwBaseLable *lable = [[LzwBaseLable alloc]initWithFrame:CGRectMake(40 * WIDTH, 0, 40 * WIDTH, 20 * WIDTH)];
    lable.text = @"去购物";
//    lable.textColor = [UIColor lightGrayColor];
    lable.font = [UIFont systemFontOfSize:12 * WIDTH];
    [self.buttonShop addSubview:lable];

  [self.contentView addSubview:self.buttonShop];

    
    
    
    //添加喜爱和购物按钮触发事件
    [self.buttonLike addTarget:self action:@selector(ButtonLike:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.buttonShop addTarget:self action:@selector(buttonShop:) forControlEvents:UIControlEventTouchUpInside];
    
    [_ImageView1 release];
    [_ImageView2 release];
    [_ImageView3 release];
    [_LableAdree6 release];
    [_LableAdree1 release];
    [_LableAdree2 release];
    [_LableAdree3 release];
    [_LableAdree4 release];
    
}

//实现三个按钮触发的事件
//关注按钮
- (void)ButtonAction:(LzwBaseButton *)but{
    
    
    [self.myAddreeshopDele AttentionButtion:self.modleSma];

    
}

//喜欢按钮
- (void)ButtonLike:(LzwBaseButton *)button{
    
    NSLog(@"我喜欢");
}

- (void)buttonShop:(LzwBaseButton *)butto{
    
    
    
        [self.myAddreeshopDele pushShoppingPage:nil];
       
 
}

//进行赋值
-(void)setModleSma:(LzwModleSmall *)modleSma{
    
    if (_modleSma != modleSma) {
        [_modleSma release];
        _modleSma = [modleSma retain];
    }
    
        
     //更新时间
    self.LableAdree2.text = self.modleSma.datestr;
    //说明
    self.LableAdree3.text = self.modleSma.content;
    
    //喜欢人数
    self.LableAdree6.text = [self.modleSma.dynamic objectForKey:@"likes"];
    
//    //人物头像
    for (NSMutableDictionary *dic in self.modleSma.pics) {

        NSURL *url1 = [NSURL URLWithString:[dic objectForKey:@"url"]];
        
        [self.ImageView3 sd_setImageWithURL:url1 placeholderImage:nil];
        
        
    }
//    //人物姓名
    self.LableAdree1.text = [self.modleSma.author objectForKey:@"username"];
//
//    //图片
//    
    NSURL *url = [NSURL URLWithString:[self.modleSma.author objectForKey:@"avatar"]];
    
    [self.ImageView1 sd_setImageWithURL:url placeholderImage:nil];
    
}
@end
